package net.ikenna.yadet.core.data;

import net.ikenna.yadet.core.cellprocessor.*;

import java.util.*;

public class ListRowSet implements RowSet {
    private List<Row> list;

    public ListRowSet(List<Row> list) {
        this.list = list;
    }

    public ListRowSet() {
        list = new ArrayList<Row>();
    }

    public List<Row> getRows() {
        return list;
    }

    public void addRow(Row row) {
        list.add(row);
    }

    public boolean contains(Row row) {
        return list.contains(row);
    }

    public RowSet processWith(CellProcessor cellProcessor) {
        RowSet results = new ListRowSet();
        for (Row row : list){
            Row processedRow = row.processWith(cellProcessor);
            results.addRow(processedRow);
        }
        return results;
    }

    public static ListRowSet from(List<Map> mapList) {
        List<Row> listOfRows = new ArrayList<Row>();
        for (Map map : mapList){
            listOfRows.add(new MapRow(map));
        }
        return new ListRowSet(listOfRows);
    }
}